package com.xinqi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinqi.bean.Goods;
import com.xinqi.mapper.GoodsMapper;
import com.xinqi.service.IGoodsService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author xin麒
 * @date 2023/2/17 15:31
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addGoods(Goods goods) {
        save(goods);//1.save一下
        //2. 添加lua脚本
        stringRedisTemplate.opsForValue().set("goods:stock:" + goods.getId(), goods.getStock().toString());
    }
}
